<template>
  <el-form ref="form" :rules="rules" label-width="100px">
    <el-form-item label="步骤名称" prop="name">
      <el-input v-model="step.name" placeholder="步骤名称"></el-input>
    </el-form-item>
    <el-button icon="plus" @click="_addRecord"></el-button>
    <br><br>
    <el-table :data="step.fields" stripe :max-height="300">
      <el-table-column type="index" width="60"></el-table-column>
      <el-table-column label="名称" width="120">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.name}}</div>
          <div v-else>
            <el-input v-model="scope.row.name" size="mini"></el-input>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="变量" width="120">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.variable}}</div>
          <div v-else>
            <el-input  v-model="scope.row.variable" size="mini"></el-input>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="类型" width="120" >
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.type}}</div>
          <div v-else>
            <el-select v-model="scope.row.type" size="mini">
              <el-option v-for="item in options.inputTypes" :value="item"></el-option>
            </el-select>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="120" >
        <template scope="scope">
          <el-row>
            <el-col :span="12">
              <el-button size="mini" type="info" @click="reverseEditState(scope.$index, scope.row)">编辑</el-button>
            </el-col>
            <el-col :span="12">
              <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </el-col>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
  </el-form>
</template>
<script>
  import {Steps,Fields,Options} from "../../model/DataModel";
  import StepCommon from "./mixins/StepMixin";
  /**
   * 获取变量step 输出字段fields.name
   * */
  export default{
    mixins: [StepCommon],

    data(){
      return {
        options:Options,
        step: Steps.GetVariable()
      }
    },

    methods:{
      updateFields(){
          this.step.outputFields = this.step.fields.map(el =>el.name);
      }
    }
  }
</script>
